import java.util.*;
import java.util.logging.FileHandler;
import java.util.logging.Handler;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.io.*;
import java.util.logging.*;

class UseProperties {
	public static void main(String[] args) {
		Properties prop = new Properties();
		try{
			//loading file content into data structure prop
			prop.load(new FileInputStream("test.properties"));
		}catch(IOException e){}
		//getting one property
		String name = prop.getProperty("name");
		System.out.println("The name is "+name);
		//changing the value property value in the data structure
		prop.setProperty("name", "matan");
		prop.setProperty("array", "{1,2,3,4}");
		try{
			//storing the updated data structure in new_test.properties file 
			prop.store(new FileOutputStream("new_test.txt"), null);
		}catch(IOException e){}
		
		// creating logger called TestingLog
		Logger logger = Logger.getLogger("TestingLog");
		Handler fh= null;
		try{
			fh = new FileHandler("my_log.log");
		}catch(IOException e){}

		//logger output is written to a file in fh handler - my_log.log
		logger.addHandler(fh);
		fh.setLevel(Level.FINEST);
		//Set the log level specifying which message levels will be logged by this logger
		logger.setLevel(Level.FINEST);
		int counter = 0;
		String line ="";
		try {
			BufferedReader br = new BufferedReader(new FileReader("foo.txt"));
			logger.fine("Input file 'foo.txt' opened.");

			try {
				while (line != null) {
					line = br.readLine();
					counter++;
				}
				//writing logging messages
				logger.fine("EOF encountered. Number of lines is + "+counter);

				br.close();
				logger.fine("Input file closed.");

			} catch(IOException ex) {
				logger.severe(ex.toString());
			}
			System.out.println("Finished");
		}catch (Exception e1){System.exit(1);}

	}
}
